<template>
  <Row v-loading="spinShow" class="layout-content-body">
    <dtable :columns="columns"
            :dataAll="dataAll"
            :dataShow="dataShow"
            @delCheck="delCheck"
            @refresh="getall()"
            @show="show"
            v-loading="spinShow"></dtable>
  </Row>
</template>
<script>
  import api from '../../api'
  import {mapMutations, mapGetters, mapState} from 'vuex'
  import dtable from '../../components/table/dtable.vue'
  export default {
    data () {
      return {
        loading: true,
        columns: [
          //多选框
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            title: '操作者',
            width: 120,
            key: 'Creater',
            sortable: true
          },
          {
            title: '所属组织',
            width: 280,
            key: 'OrgName',
            sortable: true,
          },
          {
            title: '操作内容',
            width: 320,
            key: 'Contect',
            sortable: true,
          },
          {
            title: '操作日期',
            width: 320,
            key: 'Ctime',
            sortable: true
          },
          {
            title: '操作IP',
            key: 'Ip',
          },
        ],
        dataShow: true,//是否显示表格数据查看表单
        dataAll: [],
        spinShow: false,
        editData: false,
      }
    },
    components: {
      dtable,
    },
    computed: {
      ...mapState(['isLogin', 'captchaUrl', 'cptId', 'msg']),
      filiterTableDate(){
        let e = this.dataAll.slice()
        let keys = this.searchKey
        let filterData = function (element) {
          if (keys === "") {
            return true
          }
          for (let o in element) {
            if (String(element[o]).indexOf(keys) >= 0) {
              return true
            }
          }
          return false
        }
        let fdata = e.filter(filterData)
        this.total = fdata.length
        return fdata
      },
      curTableData() {
        let from = this.pageSize * (this.current - 1)
        let to = from + this.pageSize
        return this.filiterTableDate.slice(from, to)
      },
    },
    watch: {},
    methods: {
      getall (){
        this.spinShow = true
        api.getLog().then(response => {
          if (response.data.code === 0) {
            this.dataAll = response.data.Data
            this.total = (response.data.Data).length
          } else {
            this.$Message.error(this.msg)
          }
        })
        setTimeout(() => {
          this.spinShow = false;
        }, 300);
      },
      show (row) {
        this.showItem = row
        this.showData = true
      },
      delCheck(row){
        console.log("sdsdsds",row)
        api.deleteLogs(row).then(response => {
          if (response.data.code === 0) {
            this.getall()
            this.$Message.success(this.msg)
          } else {
            this.$Message.error(this.msg, 4)
          }
        }, err => {
          this.$Message.error(this.msg, 4)
        })
      },
    },
    mounted (){
      let self = this
      self.getall()
    }
  }
</script>


